<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   
      <link rel="stylesheet" href="helpwin.css">
      <title>MATLAB File Help: woody</title>
   </head>
   <body>
      <!--Single-page help-->
      <table border="0" cellspacing="0" width="100%">
         <tr class="subheader">
            <td class="headertitle">MATLAB File Help: woody</td>
            <td class="subheader-left"><a href="woody.m">View code for woody</a></td>
            <td class="subheader-right"><a href="Contents.html">WFDB Contents</a></td>
         </tr>
      </table>
      <div class="title">woody</div>
      <div class="helptext"><pre><!--helptext -->


function [out]=woody(x,varargin)

 [out]=woody(x,tol,max_it,est_mthd,xcorr_mthd)

 Weighted average using Woody average for a signal
 with jitter. Parameters:

 x             Signal measurements. Each COLUMN represents
               and independent measure of the signal (or channel).
 tol           Tolerance paremeter to stop average (default is 0.1)
 max_it        Maximum number of iterations done on the average (default is 100).
 est_mthd      Estimation method to use. Options are:
               'woody'     : classical approach (default)
               'thornton'  : implements the Thornton approach that is also useful for different noise sources.
 xcorr_mthd    Determines what estimation method to use for the estimating the correlaation function using the
               XCORR function. Options are:
               'biased'   - scales the raw cross-correlation by 1/M.
               'unbiased' - scales the raw correlation by 1/(M-abs(lags)). (Default)
 out           Final averaged waveform (time aligned).



 Written by Ikaro Silva 

 Since 0.9.5

 %%%Example 1 %%%%
 t=[0:1/1000:1];
 N=1001;
 x=sin(2*pi*t)+sin(4*pi*t)+sin(8*pi*t);
 y=exp(0.01*[-1*[500:-1:1] 0 -1*[1:500]]);
 s=x.*y;
 sig1=0;
 sig2=0.1;
 M=100;
 S=zeros(N,M);
 center=501;
 TAU=round((rand(1,M)-0.5)*160);
 for i=1:M,
     tau=TAU(i);
     
     if(tau<0)
         S(:,i)=[s(-1*tau:end)'; zeros(-1*(tau+1),1)];
     else
         S(:,i)=[zeros(tau,1);s(1:N-tau)'; ];
     end
     if(i<50)
        S(:,i)=S(:,i) + randn(N,1).*sig1;
     else
         S(:,i)=S(:,i) + randn(N,1).*sig2;
     end
 end
 
 [wood]=woody(S,[],[],'woody','biased');
 [thor]=woody(S,[],[],'thornton','biased');
 figure;
 subplot(211)
 plot(s,'b','LineWidth',2);grid on;hold on;plot(S,'r');plot(s,'b','LineWidth',2)
 legend('Signal','Measurements')
 subplot(212)
 plot(s);hold on;plot(mean(S,2),'r');plot(wood,'g');plot(thor,'k')
 legend('Signal','Normal Ave','Woody Ave','Thornton Ave');grid on

</pre></div><!--after help -->
   </body>
</html>
